//
//  ZZCMusicPlayerViewController.m
//  B段项目
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCMusicPlayerViewController.h"
#import "AppDelegate.h"
#import "ZZCStartView.h"
#import "ZZCPlayingView.h"
#import "ZZCSongDescriptionView.h"
#import "ZZCAuthorDescription.h"
#import "ZZCPlayListTableViewCell.h"
#import "ZZCPlayListModel.h"
#import "TORadioViewController.h"
@interface ZZCMusicPlayerViewController ()<UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate, authorDesDeleage>

@property(nonatomic, retain)UIScrollView *playerScrollView;
@property(nonatomic, retain)UITableView *playListTableView;
@property(nonatomic, retain)UIView *greenSelectCell;
@property(nonatomic, retain)ZZCStartView *startView;
@property(nonatomic, retain)UIButton *backButton;
@property(nonatomic, retain)UIView *rightView;
@property(nonatomic, retain)UILabel *titleLabel;

@property(nonatomic,retain)ZZCPlayingView *playingView;
@property(nonatomic,retain)ZZCSongDescriptionView *songDescriptionView;
@property(nonatomic,retain)ZZCAuthorDescription *authorDescription;
@property(nonatomic,retain)NSTimer *myTimer;
@property(nonatomic,retain)NSMutableDictionary *musicDic;
@property(nonatomic,assign)NSInteger indexRow;//记录上一页点击cell的下标
@property(nonatomic,retain)NSMutableArray *listArray;
@property(nonatomic,retain)NSMutableArray *authorArray;
@property(nonatomic,retain)UIImageView *startImage;

@property(nonatomic,assign)BOOL isDid;

@end

@implementation ZZCMusicPlayerViewController

+(instancetype)shareMusicPlayerViewController{
    static ZZCMusicPlayerViewController *shareMusicPlayerVC = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareMusicPlayerVC = [[ZZCMusicPlayerViewController alloc]init];
    });
    return shareMusicPlayerVC;
}


#pragma mark - 页面将要消失的时候触发的方法

-(void)viewWillDisappear:(BOOL)animated{
    [self.backButton removeFromSuperview];
    [self.rightView removeFromSuperview];
    [self.titleLabel removeFromSuperview];
    
}


#pragma mark - 页面将要出现的时候触发的方法

-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    #pragma mark  判断是否是从 home页 跳进来的
        if([[[NSUserDefaults standardUserDefaults]objectForKey:@"from"]isEqualToString:@"HomePush"]){
    
            self.listArray = [NSMutableArray array];
            for (NSMutableDictionary *dic in self.musicModel.playList) {
                ZZCPlayListModel *listModel = [[ZZCPlayListModel alloc]init];
                [listModel setValuesForKeysWithDictionary:dic];
                [self.listArray addObject:listModel];
            }
    
            if (self.musicModel._id != self._id){
                self._id = self.musicModel._id;
    
                [self requestData];
                [self.playListTableView reloadData];
                self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
   
            }else{
                [self.player resume];
    
                self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
            }
    
    
    #pragma mark  判断是否是从首页轮播图跳进来的
        }else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"from"] isEqualToString:@"lun"]){
            
            self._id = self._id;
            self.listArray = [NSMutableArray array];
            [self requestData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
            NSLog(@"%@", self.listArray);
            
    #pragma mark  判断是否是从 电台页 跳进来的
        }else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"from"] isEqualToString:@"RadioPush"]){
    
            [[NSUserDefaults standardUserDefaults] setObject:@"RadioPush" forKey:@"out"];
    
            //清空播放列表数组
            self.listArray = [NSMutableArray array];
            //给播放列表的数组传值
            for (NSMutableDictionary *dic in self.radioArray) {
                ZZCPlayListModel *listModel = [[ZZCPlayListModel alloc]init];
                [listModel setValuesForKeysWithDictionary:dic];
                [self.listArray addObject:listModel];
            }
    
            //如果不是同一个id 重新赋值
            if (self.ting_id != self._id){
                self._id = self.ting_id;
    
                [self requestData];
                [self.playListTableView reloadData];
                self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
    
            }else{
                //如果是同一个id 继续播放
                [self.player resume];
    
                self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
            }
    
    #pragma mark 判断是否是从 搜索 跳转过来的
        }else if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"from"] isEqualToString:@"SearchPush"]){
    
            [[NSUserDefaults standardUserDefaults]setObject:@"SearchPush" forKey:@"out"];
    
            self._id = self.ting_id;
    
            [self requestData];
            [self.playListTableView reloadData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
    
    
    #pragma mark 判断是否是从 收藏 跳转过来的
        }else if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"from"] isEqualToString:@"CollectPush"]){
    
    
            [[NSUserDefaults standardUserDefaults]setObject:@"CollectPush" forKey:@"out"];
            self._id = self.ting_id;
    
            [self requestData];
            [self.playListTableView reloadData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//播放按钮 暂停图标
    
    
    #pragma mark 判断是否是从 抽屉 跳转过来的
        }else if([[[NSUserDefaults standardUserDefaults]objectForKey:@"from"]isEqualToString:@"FootPush"]){
    
            [[NSUserDefaults standardUserDefaults]setObject:@"FootPush" forKey:@"out"];
    
        }
    
    //通知 抽屉 变为停止
    [[NSNotificationCenter defaultCenter]postNotificationName:@"stop" object:nil];
    
    
    
    //创建返回按钮
    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.height, self.navigationController.navigationBar.frame.size.height);
    self.backButton.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.backButton];
    
    
    //创建返回图标放在返回按钮上
    UIImageView *backButtonImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 2, self.backButton.frame.size.width / 2)];
    backButtonImage.image = [UIImage imageNamed:@"iconfont-houtui.png"];
    [self.backButton addSubview:backButtonImage];
    
    //返回按钮方法
    [self.backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //创建一个空View顶替系统LeftBar
    UIView *nilView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:nilView];
    
    
    //自定义右边View
    self.rightView = [[UIView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width + 1, 0, self.navigationController.navigationBar.frame.size.width - self.backButton.frame.size.width - 1, self.navigationController.navigationBar.frame.size.height)];
    self.rightView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.rightView];
    
    
    //创建label(navigationItem.title)来显示每页标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.rightView.height / 4, self.rightView.height / 4, WIDTH-WIDTH/4, self.rightView.height / 2)];
    [self.rightView addSubview:self.titleLabel];
    
    
    self.greenSelectCell.origin = CGPointMake(0, 0);
    self.playerScrollView.contentOffset = CGPointMake(WIDTH, 0);

}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
    //底部音频播放控制器
    self.startView = [[ZZCStartView alloc]initWithFrame:CGRectMake(0, self.view.height / 13 * 11-64, self.view.width, self.view.height / 13 * 2)];
    self.startView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.startView];
//    [self.startView mas_makeConstraints:^(MASConstraintMaker *make) {
//       
//        make.left.mas_equalTo(self.view.mas_left);
//        make.top.mas_equalTo(HEIGHT * 0.75);
//        make.width.equalTo(self.view.mas_width);
//        make.height.equalTo(self.view.mas_height).multipliedBy(0.1);
//    }];
    
    
    //创建底层Scrollview
    self.playerScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, self.view.width, self.view.height / 13 * 11 -64)];
    self.playerScrollView.contentSize = CGSizeMake(self.view.width * 4, self.view.height / 13 * 11-64);
    self.playerScrollView.contentOffset = CGPointMake(self.view.width, 0);
    self.playerScrollView.pagingEnabled = YES;
    self.playerScrollView.showsHorizontalScrollIndicator = NO;
    self.playerScrollView.bounces = NO;
    self.playerScrollView.delegate = self;
    [self.view addSubview:self.playerScrollView];
    
    
    //创建播放列表tableView
    self.playListTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,  self.rightView.height, self.view.width, self.playerScrollView.height  - self.rightView.height) style:UITableViewStylePlain];
    self.playListTableView.delegate = self;
    self.playListTableView.dataSource = self;
    [self.playerScrollView addSubview:self.playListTableView];
    [self.playListTableView registerClass:[ZZCPlayListTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.playListTableView reloadData];
    self.greenSelectCell = [[UIView alloc]init];
    
    
    //创建正在播放PlayingView
    self.playingView = [[ZZCPlayingView alloc]initWithFrame:CGRectMake(self.view.width,  self.rightView.height, self.view.width, self.playerScrollView.height  - self.rightView.height)];
    [self.playerScrollView addSubview:self.playingView];
    
    
    //创建音频简介SongDescriptionView
    self.songDescriptionView = [[ZZCSongDescriptionView alloc]initWithFrame:CGRectMake(self.view.width * 2,  self.rightView.height, self.view.width, self.playerScrollView.height - self.rightView.height)];
    [self.playerScrollView addSubview:self.songDescriptionView];
    
    
    //创建主播简介AuthorDescription
    self.authorDescription = [[ZZCAuthorDescription alloc]initWithFrame:CGRectMake(self.view.width * 3,  self.rightView.height, self.view.width, self.playerScrollView.height - self.rightView.height)];
    [self.playerScrollView addSubview:self.authorDescription];
    //签协议
    self.authorDescription.authorDeleage = self;
    //主播界面 全部电台按钮
    [self.authorDescription.checkAllRadio addTarget:self action:@selector(checkAllRadioAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //列表绿色小滑条
    self.greenSelectCell.frame = CGRectMake(0, 0, 10, self.playListTableView.frame.size.height / 7);
    self.greenSelectCell.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:198/255.0 blue:121 / 255.0 alpha:1.0];
    [self.playListTableView addSubview:self.greenSelectCell];
    
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    
    
    //播放
    [self.startView.startButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //上一曲按钮
    [self.startView.nextMusicButton addTarget:self action:@selector(nextMusicAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //下一曲按钮
    [self.startView.lastMusicButton addTarget:self action:@selector(lastMusicAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //playlist  播放列表
    //playing   正在播放
    //SongDescription  歌曲简介
    //AnchorDescription  主播简介
    
#pragma mark  播放器对象
    self.player = [[STKAudioPlayer alloc]initWithOptions:(STKAudioPlayerOptions){ .flushQueueOnSeek = YES, .enableVolumeMixer = YES, .equalizerBandFrequencies = {50, 100, 200, 400, 800, 1600, 2600, 16000} } ];
    
    //定时器
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeAction:) userInfo:nil repeats:YES];
    
    [self.playingView.musicSlider addTarget:self action:@selector(slderAction) forControlEvents:UIControlEventValueChanged];
    
    
    //初始化
    self.listArray = [NSMutableArray array];
    
    
    
    //单曲
    [self.playingView.danQuButton addTarget:self action:@selector(danQuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //随机
    [self.playingView.suiJiButton addTarget:self action:@selector(suiJiButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //列表
    [self.playingView.ListButton addTarget:self action:@selector(ListButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark - 主播页代理方法
-(void)sendAuthorDescriptionTingid:(NSString *)tingid
{
    self._id = tingid;
    
    [self.playerScrollView setContentOffset:CGPointMake(WIDTH, 0) animated:YES] ;
    [self requestData];
    
}

#pragma mark - 请求数据
-(void)requestData{
    
    NSString *urlStr = @"http://api2.pianke.me/ting/info";
    NSString *body = [NSString stringWithFormat: @"auth=&client=1&deviceid=9573086A-0F03-4529-818F-432267320CE8&tingid=%@&version=3.0.6",self._id];
    [ZYTools postUrl:urlStr body:body result:ZYJSON requestStyle:ZYRequestString headerFile:nil success:^(id result) {
        
        NSMutableDictionary *bigDic = [result objectForKey:@"data"];
        ZZCPlayListModel *playModel = [[ZZCPlayListModel alloc]init];
        [playModel setValuesForKeysWithDictionary:[bigDic objectForKey:@"playInfo"]];
        
        self.authorArray = [NSMutableArray array];
        self.authorArray = [bigDic objectForKey:@"moreting"];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"from"] isEqualToString:@"lun"])
        {
            [self.listArray addObject:playModel];
            [self.playListTableView reloadData];
        }
        
        //抽屉 播放栏通知传值
        ZZCPlayListModel *musicDataModel = [[ZZCPlayListModel alloc]init];
        [musicDataModel setValuesForKeysWithDictionary:[bigDic objectForKey:@"playInfo"]];
//        NSLog(@"%@", [bigDic objectForKey:@"playInfo"]);
        [[NSNotificationCenter defaultCenter]postNotificationName:@"setData" object:musicDataModel];
        
        //播放
        NSString *url = [[bigDic objectForKey:@"playInfo"]objectForKey:@"musicUrl"];
        NSLog(@"%@", url);
        [self.player playURL:[NSURL URLWithString:url]];
        
        
        //authorDescription 主播界面 传值
        self.authorDescription.autorDic = bigDic;
        
        //playingView   播放器界面 传值
        self.playingView.playModel = playModel;
        
        //songDescriptionView  传值
        [self.songDescriptionView setWebUrl:playModel.webview_url];
        
        //播放器标题
        self.titleLabel.text = self.playingView.musicTitle.text;
        
        //绿色小条坐标
        int count = 0;
        for (int i = 0; i < self.listArray.count; i++){
            
            ZZCPlayListModel *listModel = [self.listArray objectAtIndex:i];
            if ([listModel.tingid isEqualToString:self._id]) {
                
                count = i;
            }
        }
        //左侧小竖条 坐标
        self.greenSelectCell.origin = CGPointMake(0, self.playListTableView.frame.size.height / 7 * count);
#pragma mark - 滚动到当前cell

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:count inSection:0];
        [self.playListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

#pragma mark - 所有电台按钮
- (void)checkAllRadioAction:(UIButton * )checkAllRadio{
    TORadioViewController *radioVC = [[TORadioViewController alloc]init];

    self.allRadioSelected = YES;
    [self.navigationController pushViewController:radioVC animated:YES];
    
}

#pragma mark - 进度条方法
-(void)slderAction{
    
    //改变播放进度
    [self.player seekToTime:self.playingView.musicSlider.value];
}

#pragma mark - 计时器方法
-(void)timeAction:(NSTimer *)timer{
    
    
        self.playingView.musicSlider.maximumValue = self.player.duration;//duration 音乐总时长
        self.playingView.musicSlider.value = self.player.progress; //当前播放时长
    
        NSInteger zongMin = (NSInteger)self.player.duration / 60;
        NSInteger zongSec = (NSInteger)self.player.duration % 60;
    
        NSInteger min = (NSInteger)(self.player.duration - self.player.progress) / 60;
        NSInteger sec = (NSInteger)(self.player.duration - self.player.progress) % 60;
    
    
        //总时间
        self.playingView.zongTime.text = [NSString stringWithFormat:@"%02ld:%02ld",zongMin,zongSec];
    
        //倒计时
        self.playingView.remainTime.text = [NSString stringWithFormat:@"%02ld:%02ld",min,sec];
        if ((NSInteger)self.playingView.musicSlider.value + 1 == (NSInteger)self.playingView.musicSlider.maximumValue) {
    
    
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"playMode"] isEqualToString:@"顺序播放"])
            {
                [self nextMusicAction:nil];
            }
            else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"playMode"] isEqualToString:@"单曲循环"])
            {
                [self requestData];
    
            }
            else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"playMode"] isEqualToString:@"随机播放"])
            {
                NSInteger count = arc4random()%(self.listArray.count + 1);
    
                ZZCPlayListModel *singleM = [self.listArray objectAtIndex:count];
                self._id = singleM.tingid;
                [self requestData];
            }
        }
    
    
}


#pragma mark - 播放
- (void)playAction:(UIButton *)playAction{
    
    if (self.player.state == STKAudioPlayerStatePaused) {
        
        
        self.startImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.startView.startButton.frame.size.width / 3 * 2 - 2, self.startView.startButton.frame.size.height / 3 * 2 - 2)];
        self.startImage.backgroundColor = [UIColor whiteColor];
        self.startImage.center = CGPointMake(self.startView.startButton.center.x, self.startView.startButton.center.y);
        self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标
        [self.startView addSubview:self.startImage];
        
        //通知 抽屉 变为停止
        [[NSNotificationCenter defaultCenter]postNotificationName:@"play" object:nil];
        
        NSLog(@"暂停");
        [self.player resume];//继续
        
    }else if (self.player.state == STKAudioPlayerStatePlaying) {
        
        self.startImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.startView.startButton.frame.size.width / 3 * 2 - 2, self.startView.startButton.frame.size.height / 3 * 2 - 2)];
        self.startImage.backgroundColor = [UIColor whiteColor];
        self.startImage.center = CGPointMake(self.startView.startButton.center.x , self.startView.startButton.center.y);
        self.startImage.image = [UIImage imageNamed:@"iconfont-bofang2.png"];//播放图标
        [self.startView addSubview:self.startImage];
        
        //通知 抽屉 变为播放
        [[NSNotificationCenter defaultCenter]postNotificationName:@"stop" object:nil];
        
        NSLog(@"播放");
        [self.player pause];//暂停
        
    }else
    {
        //        [self requestData];
        self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标
        
    }
    
    
}

#pragma mark - 上一曲
- (void)lastMusicAction:(UIButton *)lastMusicAction{


    //判断数组是不是空的
    if (self.listArray.count == 0) {
        [self requestData];
    }else{

        if (self.indexRow != 0) {
            self.indexRow = (self.indexRow - 1);

            ZZCPlayListModel *listModel = [self.listArray objectAtIndex:self.indexRow];
            self._id = listModel.tingid;
            [self requestData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标


        }else{

            self.indexRow = self.listArray.count - 1;
            ZZCPlayListModel *listModel = [self.listArray objectAtIndex:self.indexRow];
            self._id = listModel.tingid;
            [self requestData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标


        }

    }

    //左侧小竖条
    self.greenSelectCell.origin = CGPointMake(0, self.playListTableView.frame.size.height / 7 * self.indexRow);


    NSLog(@"上一曲");
}

#pragma mark - 下一曲
- (void)nextMusicAction:(UIButton *)nextMusicAction{

    
    
    //判断数组是不是空的
    if (self.listArray.count == 0) {
        [self requestData];
    }else{

        //+1后对总数取余是为了防止点击多次,数组越界
        self.indexRow = (self.indexRow + 1) % self.listArray.count;

        //如果歌曲总数大于当前播放的音乐下标
        if (self.indexRow < self.listArray.count) {

            ZZCPlayListModel *listModel = [self.listArray objectAtIndex:self.indexRow];
            self._id = listModel.tingid;
            [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"play"];
            [self requestData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标


        } else {

            [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"play"];
            //如果总数小于当前下标,直接播放取余数后的.也就是从第一首歌开始播放,用户体验是循环播放了
            [self requestData];
            self.startImage.image = [UIImage imageNamed:@"iconfont-zanting-2.png"];//暂停图标


        }

    }


    //左侧小竖条
    self.greenSelectCell.origin = CGPointMake(0, self.playListTableView.frame.size.height / 7 * self.indexRow);

    NSLog(@"下一曲");
}

#pragma mark - 返回按钮方法

- (void)backAction:(UIButton *)backAction{
    
    self.pushed = NO;
    [self.navigationController popViewControllerAnimated:YES];
    
}


#pragma mark - cell数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return self.listArray.count;
}



#pragma mark - cell高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.playListTableView.frame.size.height / 7;
}



#pragma mark -  cell赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static  NSString  *cellIdentifier = @"cell";
    ZZCPlayListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[ZZCPlayListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    cell.playListModel =  [self.listArray objectAtIndex:indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}

#pragma mark - 触摸cell时触发方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    self.indexRow = indexPath.row;
    self.greenSelectCell.origin = CGPointMake(0, self.playListTableView.frame.size.height / 7 * self.indexRow);
    
    
    ZZCPlayListTableViewCell *listCell = (ZZCPlayListTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    
        self._id = listCell.playListModel.tingid;
        [self requestData];
}




#pragma mark - 减速停止时触发(滑动结束)
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"减速停止");
    
    if (scrollView.contentOffset.x == 0) {
        self.startView.pageOne.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:198/255.0 blue:121 / 255.0 alpha:1.0];
        self.startView.pageTwo.backgroundColor = [UIColor grayColor];
        self.startView.pageThree.backgroundColor = [UIColor grayColor];
        self.startView.pageFour.backgroundColor = [UIColor grayColor];
    }else if(scrollView.contentOffset.x == self.view.frame.size.width){
        self.startView.pageTwo.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:198/255.0 blue:121 / 255.0 alpha:1.0];
        self.startView.pageOne.backgroundColor = [UIColor grayColor];
        self.startView.pageThree.backgroundColor = [UIColor grayColor];
        self.startView.pageFour.backgroundColor = [UIColor grayColor];
    }else if(scrollView.contentOffset.x == self.view.frame.size.width * 2){
        self.startView.pageThree.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:198/255.0 blue:121 / 255.0 alpha:1.0];
        self.startView.pageTwo.backgroundColor = [UIColor grayColor];
        self.startView.pageOne.backgroundColor = [UIColor grayColor];
        self.startView.pageFour.backgroundColor = [UIColor grayColor];
    }else{
        self.startView.pageFour.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:198/255.0 blue:121 / 255.0 alpha:1.0];
        self.startView.pageTwo.backgroundColor = [UIColor grayColor];
        self.startView.pageThree.backgroundColor = [UIColor grayColor];
        self.startView.pageOne.backgroundColor = [UIColor grayColor];
    }
}


#pragma mark - 单曲循环
-(void)danQuButtonAction:(UIButton *)btn{
    
    [[NSUserDefaults standardUserDefaults] setObject:@"单曲循环" forKey:@"playMode"];
    
    
    [self.playingView.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan-2.png"] forState:UIControlStateNormal];
    
    [self.playingView.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang.png"] forState:UIControlStateNormal];
    
    [self.playingView.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan.png"] forState:UIControlStateNormal];
    
    
}

#pragma mark - 随机播放
-(void)suiJiButtonAction:(UIButton *)btn{
    
    [[NSUserDefaults standardUserDefaults] setObject:@"随机播放" forKey:@"playMode"];
    
    
    [self.playingView.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang-2.png"] forState:UIControlStateNormal];
    
    
    [self.playingView.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan.png"] forState:UIControlStateNormal];
    
    [self.playingView.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan.png"] forState:UIControlStateNormal];
    
}



#pragma mark - 列表循环
-(void)ListButtonAction:(UIButton *)btn{
    
    [[NSUserDefaults standardUserDefaults] setObject:@"顺序播放" forKey:@"playMode"];
    
    
    
    [self.playingView.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan-2.png"] forState:UIControlStateNormal];
    
    [self.playingView.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan.png"] forState:UIControlStateNormal];
    
    [self.playingView.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang.png"] forState:UIControlStateNormal];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
